var express = require('express');
var router = express.Router();
var env = require('../Env');
var proxy = require('express-http-proxy');
var config = require('../config/config');
var ApiHost = '';
if( process.env.NODE_ENV === 'production' ){
    ApiHost = env.API_HOST;
}

router.use('/api', proxy('https://apitest.quantumhealth.cn',{
	https: true,
	timeout: 3000,
	// decorateRequest: function(proxyReq, originalReq) {
	// 	console.log( 'proxyReq')
	//     return proxyReq;
	// },
	intercept: function(rsp, data, req, res, callback) {
		console.log( 'intercept', data );
	    // rsp - original response from the target 
	    data = JSON.parse(data.toString('utf8'));

	    callback(null, JSON.stringify(data));
	}
}), function(req, res, next){
	console.log( 'mmmmmmmmmmmmmmm' );
});

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { apiHost: ApiHost});
});

module.exports = router;
